home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F41986_testrandom.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-04-08  |  4.7 KB  |  135 lines

  1. <xsl:stylesheet version="1.0" 
  2.  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.  xmlns:vendor="http://xml.apache.org/xalan"
  4.  xmlns:myDistribution="f:myDistribution"
  5.  exclude-result-prefixes="xsl vendor myDistribution"
  6. >
  7.  
  8.   <xsl:import href="random.xsl"/>
  9.   
  10.   <myDistribution:myDistribution>
  11.     <o>1</o><p>0.2</p>
  12.     <o>2</o><p>0.25</p>
  13.     <o>3</o><p>0.25</p>
  14.     <o>4</o><p>0.15</p>
  15.     <o>5</o><p>0.1</p>
  16.     <o>6</o><p>0.05</p>
  17.   </myDistribution:myDistribution>
  18.   
  19.   <xsl:output indent="yes" omit-xml-declaration="yes"/>
  20.   
  21.   <xsl:variable name="NL" select="' '"/>
  22.   
  23.   <xsl:template match="/">
  24.     
  25.     <xsl:variable name="vrtfUnscaledRandoms">
  26.       <xsl:call-template name="randomSequence">
  27.         <xsl:with-param name="pLength" select="100"/>
  28.       </xsl:call-template>
  29.     </xsl:variable>
  30.     
  31.     <xsl:variable name="vUnscaledRandoms" 
  32.      select="vendor:node-set($vrtfUnscaledRandoms)/*"/>
  33.     
  34. 100 Randoms in (0,<xsl:value-of select="$modulus - 1"/>):
  35.     <xsl:for-each select="$vUnscaledRandoms
  36.                              [position() mod 8 = 1]">
  37.       <xsl:value-of select="$NL"/>
  38.       <xsl:for-each 
  39.          select=". | following::*[position() < 8]">
  40.         <xsl:value-of select="concat(., ', ')"/>
  41.       </xsl:for-each>
  42.     </xsl:for-each>
  43.     
  44.     <xsl:variable name="vStart" select="1"/>
  45.     <xsl:variable name="vEnd" select="10"/>
  46.     
  47.     <xsl:value-of select="concat($NL,$NL,
  48.                                  '100 Randoms in (',
  49.                                  $vStart, ', ',
  50.                                  $vEnd, '):',
  51.                                  $NL
  52.                                  )"/> 
  53.     <xsl:variable name="vrtfScaledRandoms">
  54.       <xsl:call-template name="randomSequence">
  55.         <xsl:with-param name="pLength" select="100"/>
  56.         <xsl:with-param name="pStart" select="$vStart"/>
  57.         <xsl:with-param name="pEnd" select="$vEnd"/>
  58.       </xsl:call-template>
  59.     </xsl:variable>
  60.     
  61.     <xsl:variable name="vScaledRandoms" 
  62.        select="vendor:node-set($vrtfScaledRandoms)/*"/>
  63.     
  64.     <xsl:for-each select="$vScaledRandoms
  65.                               [position() mod 10 = 1]">
  66.       <xsl:value-of select="$NL"/>
  67.       <xsl:for-each 
  68.          select=". | following::*[position() < 10]">
  69.         <xsl:value-of select="concat(., ', ')"/>
  70.       </xsl:for-each>
  71.     </xsl:for-each>
  72.     
  73.     <xsl:value-of select="concat($NL,$NL,
  74.                                  'Randoms 11-20 in (',
  75.                                  $vStart, ', ',
  76.                                  $vEnd, '):',
  77.                                  $NL
  78.                                  )"/> 
  79.     <xsl:variable name="vrtfRandSubsequence">
  80.       <xsl:call-template name="randomSubSequence">
  81.         <xsl:with-param name="pLength" select="10"/>
  82.         <xsl:with-param name="pSubStart" select="11"/>
  83.         <xsl:with-param name="pStart" select="$vStart"/>
  84.           <xsl:with-param name="pEnd" select="$vEnd"/>
  85.       </xsl:call-template>
  86.     </xsl:variable>
  87.     
  88.     <xsl:copy-of 
  89.       select="vendor:node-set($vrtfRandSubsequence)/*"/>
  90.     
  91.     <xsl:variable name="vrtfDistRandSeq">
  92.       <xsl:call-template name="dist-randomSequence">
  93.         <xsl:with-param name="pLength" select="100"/>
  94.         <xsl:with-param name="pDist" 
  95.          select="document('')/*/myDistribution:*[1]/*"/>
  96.         
  97.       </xsl:call-template>
  98.     </xsl:variable>
  99.     
  100.     <xsl:value-of select="concat($NL,$NL,
  101.       '100 Random outcomes 1-6 with distribution: '
  102.                                  )"/> 
  103.     <xsl:copy-of 
  104.          select="document('')/*/myDistribution:*[1]"/>
  105.     <xsl:value-of 
  106.           select="concat($NL, $NL, 'Results:', $NL)"/>
  107.     
  108.     <xsl:variable name="vDistRandSeq" 
  109.          select="vendor:node-set($vrtfDistRandSeq)/*"/>
  110.     
  111.     <xsl:for-each select="$vDistRandSeq
  112.                               [position() mod 10 = 1]">
  113.       <xsl:value-of select="$NL"/>
  114.       <xsl:for-each 
  115.          select=". | following::*[position() < 10]">
  116.         <xsl:value-of select="concat(., ', ')"/>
  117.       </xsl:for-each>
  118.     </xsl:for-each>
  119.     
  120.         <xsl:value-of select="concat($NL,$NL,
  121.            'Randoms 11-20 with the same distribution:',
  122.                                  $NL
  123.                                  )"/> 
  124.     <xsl:variable name="vrtfDistRandSubsequence">
  125.       <xsl:call-template name="dist-randomSubSequence">
  126.         <xsl:with-param name="pLength" select="10"/>
  127.         <xsl:with-param name="pSubStart" select="11"/>
  128.         <xsl:with-param name="pDist" 
  129.          select="document('')/*/myDistribution:*[1]/*"/>
  130.       </xsl:call-template>
  131.     </xsl:variable>
  132.     <xsl:copy-of 
  133.     select="vendor:node-set($vrtfDistRandSubsequence)/*"/>
  134.   </xsl:template>
  135. </xsl:stylesheet>